package eerbaar.v2.wait;

import eerbaar.v2.app.core.App;

public class Wait {

    private static final Wait instance = new Wait();

    public static Wait getInstance() {
        return instance;
    }

    private int count;

    private Wait() {
        //
    }

    public int getCount() {
        return this.count;
    }

    public synchronized WaitRegistration startWaiting() {

        this.count++;
        App.instance().getLoop().setSuspended(true);

        return new WaitRegistration() {

            @Override
            public void stopWaiting() {
                Wait.this.stopWaiting();
            }
        };
    }

    public synchronized void stopWaiting() {
        this.count--;
        App.instance().getLoop().setSuspended(false);
    }

}
